

cap file close Table
pause on 

local summstats_Egypt_only				$summstats_Egypt_only

local summstats_Tunisia_only			$summstats_Tunisia_only

local all_summstats_Egypt_only    		$`summstats_Egypt_only'

local all_summstats_Tunisia_only    	$`summstats_Tunisia_only'

local title								endline_1_summstats_ge


* Produce descriptive statistics using Egypt endline 1 data 
				
	foreach outcome in `all_summstats_Egypt_only' {

	use  "Data/endline_1_egypt_fem.dta", clear 
			
			* All residents
			
				summ `outcome'
				
					local c_1_`outcome' : di%12.3f `r(mean)'
					local sd_1_`outcome' : di%12.3f `r(sd)'
					local n_1_`outcome' = `r(N)'
		
			* Treatment residents
				
				summ `outcome' if within==1
				
					local c_2_`outcome' : di%12.3f `r(mean)'
					local sd_2_`outcome' : di%12.3f `r(sd)'
					local n_2_`outcome' = `r(N)'
			
			* Partial control residents
				
				summ `outcome' if within==0
				
					local c_3_`outcome' : di%12.3f `r(mean)'
					local sd_3_`outcome' : di%12.3f `r(sd)'
					local n_3_`outcome' = `r(N)'

			* Pure control residents
				
				summ `outcome' if between==0
				
					local c_4_`outcome' : di%12.3f `r(mean)'
					local sd_4_`outcome' : di%12.3f `r(sd)'
					local n_4_`outcome' = `r(N)'
					
			* All community members
				
				summ `outcome' if infrastructure!=.
				
					local c_5_`outcome' : di%12.3f `r(mean)'
					local sd_5_`outcome' : di%12.3f `r(sd)'
					local n_5_`outcome' = `r(N)'

			* Treatment community members
				
				summ `outcome' if infrastructure==1
				
					local c_6_`outcome' : di%12.3f `r(mean)'
					local sd_6_`outcome' : di%12.3f `r(sd)'
					local n_6_`outcome' = `r(N)'

			* Control community members
				
				summ `outcome' if infrastructure==0
				
					local c_7_`outcome' : di%12.3f `r(mean)'
					local sd_7_`outcome' : di%12.3f `r(sd)'
					local n_7_`outcome' = `r(N)'
			
					
					
	}
				
	foreach outcome of local all_summstats_Egypt_only {
		
		 local l_`outcome' : variable label `outcome'
		
	}

				
			

	
* Produce descriptive statistics using Tunisia endline 1 data 

	foreach outcome in `all_summstats_Tunisia_only' {

	use  "Data/endline_1_tunisia_fem.dta", clear 
					
			* All residents
			
				summ `outcome'
				
					local c_8_`outcome' : di%12.3f `r(mean)'
					local sd_8_`outcome' : di%12.3f `r(sd)'
					local n_8_`outcome' = `r(N)'
		
			* Treatment residents
				
				summ `outcome' if within==1
				
					local c_9_`outcome' : di%12.3f `r(mean)'
					local sd_9_`outcome' : di%12.3f `r(sd)'
					local n_9_`outcome' = `r(N)'
			
			* Partial control residents
				
				summ `outcome' if within==0
				
					local c_10_`outcome' : di%12.3f `r(mean)'
					local sd_10_`outcome' : di%12.3f `r(sd)'
					local n_10_`outcome' = `r(N)'

			* Pure control residents
				
				summ `outcome' if between==0
				
					local c_11_`outcome' : di%12.3f `r(mean)'
					local sd_11_`outcome' : di%12.3f `r(sd)'
					local n_11_`outcome' = `r(N)'
					
			* All community members
				
				summ `outcome' if infrastructure!=.
				
					local c_12_`outcome' : di%12.3f `r(mean)'
					local sd_12_`outcome' : di%12.3f `r(sd)'
					local n_12_`outcome' = `r(N)'


			* Treatment community members
				
				summ `outcome' if infrastructure==1
				
					local c_13_`outcome' : di%12.3f `r(mean)'
					local sd_13_`outcome' : di%12.3f `r(sd)'
					local n_13_`outcome' = `r(N)'

			* Control community members
				
				summ `outcome' if infrastructure==0
				
					local c_14_`outcome' : di%12.3f `r(mean)'
					local sd_14_`outcome' : di%12.3f `r(sd)'
					local n_14_`outcome' = `r(N)'
					
	}
				
				
						

	
	foreach outcome of local all_summstats_Tunisia_only {
		
		 local l_`outcome' : variable label `outcome'
		
	}

	
	
* Save tables to Dropbox


	file open Table using "Output/`title'.tex", text write replace

	file write Table  _n ///
	"\begin{tabular}{l*{10}{c}}\hline&\multicolumn{3}{c}{\textbf{All}}&\multicolumn{3}{c}{\textbf{Treatment}} &\multicolumn{3}{c}{\textbf{Control}} \\ \cmidrule(r){2-4}\cmidrule(l){5-7} \cmidrule(l){8-10} & {Mean} & {SD} & {N} & {Mean} & {SD} & {N} & {Mean} & {SD} & {N} \\ \cmidrule(r){2-4}\cmidrule(l){5-7} \cmidrule(l){8-10}  & {(1)} & {(2)} & {(3)} & {(4)} & {(5)} & {(6)} & {(7)} & {(8)} & {(9)}  \\ \midrule \multicolumn{1}{p{1.3cm}}{\textbf{Egypt}} & &  &    \\ \cmidrule(r){1-4}\cmidrule(l){5-7} \cmidrule(l){8-10} "   _n

	foreach outcome of local all_summstats_Egypt_only {
		
	file write Table																																	_n ///
	"`l_`outcome'' & `c_5_`outcome''  & `sd_5_`outcome'' & `n_5_`outcome'' & `c_6_`outcome'' & `sd_6_`outcome'' & `n_6_`outcome'' & `c_7_`outcome'' & `sd_7_`outcome''   & `n_7_`outcome''                                                                                          \\"  _n 
	}

	file write Table  _n ///
	"\cmidrule(r){1-4}\cmidrule(l){5-7} \cmidrule(l){8-10}  \multicolumn{1}{p{1.3cm}}{\textbf{Tunisia}} & &  &    \\ \cmidrule(r){1-4}\cmidrule(l){5-7} \cmidrule(l){8-10}  "   _n


	foreach outcome of local all_summstats_Tunisia_only {
		
		file write Table                   _n ///
	"`l_`outcome'' & `c_12_`outcome''  & `sd_12_`outcome'' & `n_12_`outcome'' & `c_13_`outcome'' & `sd_13_`outcome'' & `n_13_`outcome'' & `c_14_`outcome'' & `sd_14_`outcome''   & `n_14_`outcome''                                                                                         \\"  _n 
	}

	file write Table					_n ///
			"\hline \end{tabular}"													_n

	file close Table

